<#assign content>
<div class="right_col" role="main">
    <div class="">
        <div class="page-title">
            <div class="title_left">
                <h3>设备参数列表</h3>
            </div>
            <div class="title_right">
            </div>
        </div>
        <div class="clearfix"></div>
        <div class="row">
            <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="x_panel">
                    <div class="x_title">
                        <h2>
                            <small></small>
                        </h2>
                        <ul class="nav navbar-right panel_toolbox">
                            <li><a id="deviceTechAdd"><i class="fa fa-plus-circle"></i></a></li>
                            <li><a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
                            </li>
                        </ul>
                        <div class="clearfix"></div>
                    </div>
                    <div class="x_content">
                    <#--产品信息显示-->
                        <div class="alert alert-info alert-dismissible fade in" role="alert">
                            <#--<#if sProduct.price?exists>
                                <#assign price = MoneyTag.priceToString(sProduct.price) />
                            <#else>
                                <#assign price = 0 />
                            </#if>-->
                            <#if sDevice?exists><strong>设备名称：<#if sDevice.name?exists>${sDevice.name}</#if></strong></#if>
                        </div>
                        <div style="display: none"></div>
                    <#--设备参数-->
                        <#if deviceTechList?exists && deviceTechList?size gt 0>
                            <#list deviceTechList as deviceTechList>
                                <div class="col-md-4 col-sm-4 col-xs-12 profile_details">
                                    <div class="well profile_view" style="width: 100%">
                                        <div class="col-sm-12">
                                            <p><strong>参数标识：${deviceTechList.tkey}</strong></p>
                                            <p><strong>最低阀值：${deviceTechList.minval}</strong></p>
                                            <p><strong>最高阀值：${deviceTechList.maxval}</strong></p>
                                            <#if deviceTechList.flag==true>
                                                <p><strong>状态：<span style="color: #00CC33">正常</span></strong></p>
                                            <#else>
                                                <p><strong>状态：<span style="color: #be2626">已删除</span></strong></p>
                                            </#if>
                                        </div>
                                        <div class="col-xs-12 bottom text-center">
                                            <div class="col-xs-12 col-sm-12 emphasis">
                                                <button onclick="$.deviceTechEdit(${deviceTechList.id})" type="button" class="btn btn-success btn-xs"><i class="fa fa-pencil"></i>修改</button>
                                                <button onclick="$.deviceTechDelete(${deviceTechList.id})" type="button" class="btn btn-danger btn-xs"><i class="fa fa-trash-o"></i>删除</button>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </#list>
                        </#if>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</#assign>
<#include "../_inc/layout.ftl" />
<#--//增加设备参数-->
<div class="modal fade" id="deviceTechAddModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
     aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content" style="width: 700px;">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">添加设备参数</h4>
            </div>
            <form id="deviceTechAddForm" method="post" novalidate class="form-horizontal form-label-left">
                <input type="hidden" id="add_device_id" name="deviceId">
                <div class="modal-body">
                    <div class="item form-group">
                        <label class="control-label col-md-3">参数标识<span class="required">*</span>
                        </label>
                        <div class="col-md-5">
                            <input type="text" id="techAddTkey" name="tkey" data-validate-length-range="5,12"
                                   placeholder="请输入参数标识" required="required" class="form-control col-md-6">
                        </div>
                    </div>
                    <div class="item form-group">
                        <label class="control-label col-md-3">最低阀值<span class="required">*</span>
                        </label>
                        <div class="col-md-5">
                            <input type="text" id="techAddMinval" name="minval" data-validate-length-range="5,12"
                                   placeholder="请输入最低阀值" required="required" class="form-control col-md-6">
                        </div>
                    </div>
                    <div class="item form-group">
                        <label class="control-label col-md-3">最高阀值<span class="required">*</span>
                        </label>
                        <div class="col-md-5">
                            <input type="text" id="techAddMaxval" name="maxval" data-validate-length-range="5,12"
                                   placeholder="请输入最高阀值" required="required" class="form-control col-md-6">
                        </div>
                    </div>
                    <div class="item form-group">
                        <label class="control-label col-md-3">描述
                        </label>
                        <div class="col-md-5">
                            <input type="text" id="techAddRemark" name="remark" data-validate-length-range="5,12"
                                   placeholder="请输入描述" class="form-control col-md-6">
                        </div>
                    </div>
                </div>
                <div class="ln_solid"></div>
                <div class="form-group">
                    <div class="col-md-8 col-md-offset-9">
                        <button id="saveDeviceTech" type="button" class="btn btn-success">保存</button>
                        <button class="btn btn-primary" type="reset">重置</button>
                    </div>
                </div>
            </form>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>

<#--//修改设备参数-->
<div class="modal fade" id="deviceTechEdit" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
     aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content" style="width: 700px;">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">修改设备参数</h4>
            </div>
            <form id="deviceTechEditForm" method="post" novalidate class="form-horizontal form-label-left">
                <input type="hidden" id="edit_deviceTech_id" name="deviceTechId">
                <input type="hidden" id="edit_device_id" name="deviceId">
                <div class="modal-body">
                    <div class="item form-group">
                        <label class="control-label col-md-3">参数标识<span class="required">*</span>
                        </label>
                        <div class="col-md-5">
                            <input type="text" id="techEditTkey" name="tkey" data-validate-length-range="5,12"
                                   placeholder="请输入参数标识" required="required" class="form-control col-md-6">
                        </div>
                    </div>
                    <div class="item form-group">
                        <label class="control-label col-md-3">最低阀值<span class="required">*</span>
                        </label>
                        <div class="col-md-5">
                            <input type="text" id="techEditMinval" name="minval" data-validate-length-range="5,12"
                                   placeholder="请输入最低阀值" required="required" class="form-control col-md-6">
                        </div>
                    </div>
                    <div class="item form-group">
                        <label class="control-label col-md-3">最高阀值<span class="required">*</span>
                        </label>
                        <div class="col-md-5">
                            <input type="text" id="techEditMaxval" name="maxval" data-validate-length-range="5,12"
                                   placeholder="请输入最高阀值" required="required" class="form-control col-md-6">
                        </div>
                    </div>
                    <div class="item form-group">
                        <label class="control-label col-md-3">描述
                        </label>
                        <div class="col-md-5">
                            <input type="text" id="techeditRemark" name="remark" data-validate-length-range="5,12"
                                   placeholder="请输入描述" class="form-control col-md-6">
                        </div>
                    </div>
                </div>
                <div class="ln_solid"></div>
                <div class="form-group">
                    <div class="col-md-8 col-md-offset-9">
                        <button id="editDeviceTech" type="button" class="btn btn-success">保存</button>
                        <button class="btn btn-primary" type="reset">重置</button>
                    </div>
                </div>
            </form>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>

<#--// 删除设备中的设备参数-->
<div class="modal fade" id="deviceTechDelete" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
     aria-hidden="true">

    <div class="modal-dialog modal-lg">
        <div class="modal-content" style="width: 700px;">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">设备参数删除</h4>
            </div>
            <form id="deviceTechDeleteForm" method="post" novalidate class="form-horizontal form-label-left">
                <input type="hidden" id="delete_techid" name="id">
                <input type="hidden" id="detele_device_id" name="deviceId" value="${sDevice.id}">
                <div class="modal-body">
                    <div class="item form-group">
                        <div class="col-md-10">
                            <span id="deviceTechDeleteMessage"></span>
                        </div>
                    </div>
                </div>
                <div class="ln_solid"></div>
                <div class="form-group">
                    <div class="col-md-8 col-md-offset-9">
                        <button id="saveDeleteDeviceTech" type="button" class="btn btn-success">确定</button>
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    </div>
                </div>
            </form>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>

<script>

    var devicetechtable;

    $(document).ready(function () {

        // 增加设备参数
        $('#deviceTechAdd').on('click', function () {
            $('#deviceTechAddModal').modal({
                keyboard: true
            });
            $('#add_device_id').val(${deviceid});
        });

        // 窗体关闭清空页面
        $('#deviceTechAddModal').on('hide.bs.modal', function () {
            $('#deviceTechAddForm')[0].reset();
        });


        // 保存新增设备参数
        $('#saveDeviceTech').on('click', function () {
            if (validator.checkAll($('#deviceTechAddForm'))) {
                var param = {};
                param.action = 'do';
                param.deviceid = $('#add_device_id').val();
                param.tkey = $('#techAddTkey').val();
                param.minval = $('#techAddMinval').val();
                param.maxval = $('#techAddMaxval').val();
                param.remark = $('#techAddRemark').val();

                $('#deviceTechAddForm')[0].reset();
                $('#deviceTechAddModal').modal('hide');
                $.ajax({
                    type: 'POST',
                    url: '/devicetech_add.do',
                    cache: false,
                    dataType: 'json',
                    data: param,
                    success: function (result) {
                        if (result.success) {
                            var params = {};
                            params.deviceid = $('#add_device_id').val();
                            $.submitFormPost('/devicetech_list.do', params,  'POST');
                            //devicetechtable.draw(false);
                        }
                        else {
                            $.promptModal('${warning}', result.msg, result.logout);
                        }
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        $.promptModal('${warning}', '${systemException}', false);
                    }
                });
            }
        });

        // 删除设备参数
        $.deviceTechDelete = function (id) {
            $('#delete_techid').val(id);
            $('#deviceTechDeleteMessage').html('确定删除此设备参数？');
            $('#deviceTechDelete').modal({
                keyboard: true
            });
        };

        // 窗体关闭清空页面
        $('#deviceTechDelete').on('hide.bs.modal', function () {
            $('#deviceTechDeleteForm')[0].reset();
        });

        // 保存删除
        $('#saveDeleteDeviceTech').on('click', function () {
            var param = {};
            param.action = 'doDelete';
            param.id = $('#delete_techid').val();
            $('#deviceTechDelete').modal('hide');
            $.ajax({
                type: 'POST',
                url: '/devicetech_edit.do',
                cache: false,
                dataType: 'json',
                data: param,
                success: function (result) {
                    if (result.success) {
                        //devicetechtable.draw(false);
                        var params = {};
                        params.deviceid = $('#detele_device_id').val();
                        $.submitFormPost('/devicetech_list.do', params, 'POST');
                    }
                    else {
                        $.promptModal('${warning}', result.msg, result.logout);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    $.promptModal('${warning}', '${systemException}', false);
                }
            });
        });

        $('#deviceTechEdit').on('hide.bs.modal', function () {
            $('#deviceTechEditForm')[0].reset();
        });


        //修改
        $.deviceTechEdit = function (id) {
            var param = {};
            param.action = 'edit';
            param.id = id;
            $.ajax({
                type: 'POST',
                url: '/devicetech_edit.do',
                cache: false,
                dataType: 'json',
                data: param,
                success: function (result) {
                    if (result.success) {
                        $('#edit_deviceTech_id').val(id);
                        $('#edit_device_id').val(result.body.deviceTech.did);
                        $('#techEditTkey').val(result.body.deviceTech.tkey);
                        $('#techEditMinval').val(result.body.deviceTech.minval);
                        $('#techEditMaxval').val(result.body.deviceTech.maxval);
                        $('#techeditRemark').val(result.body.deviceTech.remark);
                        $('#deviceTechEdit').modal({
                            keyboard: true
                        });
                    }
                    else {
                        $.promptModal('${warning}', result.msg, result.logout);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    $.promptModal('${warning}', '${systemException}', false);
                }
            });
        };

        // 保存修改
        $('#editDeviceTech').on('click', function () {
            if (validator.checkAll($('#deviceTechEditForm'))) {
                var param = {};
                param.action = 'doEdit';
                param.id = $('#edit_deviceTech_id').val();
                param.did = $('#edit_device_id').val();
                param.tkey = $('#techEditTkey').val();
                param.minval = $('#techEditMinval').val();
                param.maxval = $('#techEditMaxval').val();
                param.remark = $('#techEditRemark').val();
                $('#deviceTechEditForm')[0].reset();
                $('#deviceTechEdit').modal('hide');
                $.ajax({
                    type: 'POST',
                    url: '/devicetech_edit.do',
                    cache: false,
                    dataType: 'json',
                    data: param,
                    success: function (result) {
                        if (result.success) {
                            var params = {};
                            params.deviceid = $('#edit_device_id').val();
                            $.submitFormPost('/devicetech_list.do', params, 'POST');
                        }
                        else {
                            $.promptModal('${warning}', result.msg, result.logout);
                        }
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        $.promptModal('${warning}', '${systemException}', false);
                    }
                });
            }
        });
    });
</script>

